<script setup>
import { ref } from 'vue'
import axios from 'axios'

const result = ref(null)

const testAxios = async () => {
  try {
    const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1')
    result.value = response.data
  } catch (error) {
    console.error('请求出错:', error)
  }
}
</script>

<template>
  <div class="test-axios">
    <h1>测试 Axios 请求</h1>
    <button @click="testAxios">发送请求</button>
    <div v-if="result" class="result">
      <h3>请求结果：</h3>
      <pre>{{ result }}</pre>
    </div>
  </div>
</template>

<style scoped>
.test-axios {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin: 20px 0;
}

button:hover {
  background-color: #45a049;
}

.result {
  margin-top: 20px;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 4px;
}

pre {
  white-space: pre-wrap;
  word-wrap: break-word;
}
</style>